package xhwl.hmo.mall.utils;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class StringUtil {
	public static boolean isEmpty(String msg)
	{
		return msg==null||msg.length()==0;
	}
	public static void highlightText(TextView tv, final String color, String text, int start, int length){
		SpannableString spannableString = new SpannableString(text);
		spannableString.setSpan(new ClickableSpan() {
			@Override
			public void updateDrawState(TextPaint ds) {
				super.updateDrawState(ds);
				ds.setColor(Color.parseColor(color));
				ds.setUnderlineText(false);
			}

			@Override
			public void onClick(View widget) {
			}
		}, start, start+length, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
		tv.setHighlightColor(Color.TRANSPARENT);//设置点击后的颜色为透明，否则会一直出现高亮
		tv.append(spannableString);
		tv.setMovementMethod(LinkMovementMethod.getInstance());//开始响应点击事件
	}

	/**
	 * 判断是否包含汉字
	 * @param str
	 * @return
	 */
	public static Boolean isContainChinese(String str) {
		for (int i = 0; i < str.length(); i++) {
			String bb = str.substring(i, i + 1);
			// 生成一个Pattern,同时编译一个正则表达式,其中的u4E00("一"的unicode编码)-\u9FA5("龥"的unicode编码)
			boolean cc = java.util.regex.Pattern.matches("[\u4E00-\u9FA5]", bb);
			if (cc == true) {
				return cc;
			}
		}
		return false;
	}
}
